home *** CD-ROM | disk | FTP | other *** search
- #include "HEADERS.h"
- #include "SPHDEMO.h"
- #include "SPHDEMO_struct.h"
- #include "SPHDEMO_view.h"
-
- #include <MenuMgr.h>
-
- extern WindowPtr srgpmac__cwindow;
-
- static MenuHandle rendermenu, chimneymenu, cameramenu, viewportmenu, pickmenu,
- gridmenu, applemenu, modelmenu;
- static int currenderitem = 6, curchimneymenuitem = 3;
- static int curgridmenuitem = 1, curvpmenuitem = 2;
- static int curCamDialogID = 0; /* resource ID of camera dialog box currently in use */
- static DialogPtr curCamDialogPtr;
-
- static int curHelpDialogID = 0;
- static DialogPtr curHelpDialogPtr;
-
- #define granDialogID 666
- static DialogPtr granDialogPtr; /* granularity dialog box */
- static Handle grantextitemhandle, tmpitemhandle;
- static DialogPtr tmpdptr;
-
- #define rendermenuID 600
- #define cameramenuID 602
- #define chimneymenuID 601
- #define viewportmenuID 604
- #define pickmenuID 605
- #define gridmenuID 603
- #define modelmenuID 606
- #define applemenuID 609
-
- #define HelpDlogFor(MENUID) (3600+MENUID)
-
- static boolean stillVirgin = TRUE;
-
-
- static void InstallCameraDialog (int whichitem)
- {
- /* UNMAP ANY EXTANT DIALOG BOX */
- if (curCamDialogID > 0)
- DisposDialog (curCamDialogPtr);
-
- /* UNCHECK ITEM IN MENU */
- if (curCamDialogID > 0)
- CheckItem (cameramenu, curCamDialogID-300, FALSE);
-
- /* MAP NEW DIALOG BOX */
- curCamDialogID = whichitem + 300;
- curCamDialogPtr = GetNewDialog (curCamDialogID, NULL, (WindowPtr)-1);
- DrawDialog (curCamDialogPtr);
- CheckItem (cameramenu, whichitem, TRUE);
- }
-
- static void InstallHelpDialog (int whichmenuid)
- {
- /* UNMAP ANY EXTANT DIALOG BOX */
- if (curHelpDialogID > 0)
- DisposDialog (curHelpDialogPtr);
-
- /* MAP NEW DIALOG BOX */
- curHelpDialogID = HelpDlogFor(whichmenuid);
- curHelpDialogPtr = GetNewDialog (curHelpDialogID, NULL, (WindowPtr)-1);
- DrawDialog (curHelpDialogPtr);
- }
-
-
-
-
- static int motion_granularity = 30;
-
- void DisplayMotionGranularity (void)
- {
- char buffer[19];
- sprintf (buffer, "%d", motion_granularity);
- CtoPstr(buffer);
- SetIText (grantextitemhandle, buffer);
- }
-
-
-
- void AddGridInFrontOfRoot (int structID, int viewID)
- {
- SPH_unpostRoot (structID, viewID);
- SPH_postRoot (GRID_STRUCT, viewID);
- SPH_postRoot (structID, viewID);
- }
-
-
- void MakeMenuBar()
- {
- InsertMenu (applemenu=GetMenu(applemenuID), 0);
- InsertMenu (rendermenu=GetMenu(rendermenuID), 0);
- InsertMenu (cameramenu=GetMenu(cameramenuID), 0);
- InsertMenu (viewportmenu=GetMenu(viewportmenuID), 0);
- InsertMenu (pickmenu=GetMenu(pickmenuID), 0);
- InsertMenu (gridmenu=GetMenu(gridmenuID), 0);
- InsertMenu (chimneymenu=GetMenu(chimneymenuID), 0);
- InsertMenu (modelmenu=GetMenu(modelmenuID), 0);
- DrawMenuBar();
- }
-
-
- void ReportSpecialError (char *message, boolean is_fatal);
-
-
- main()
- {
- EventRecord ev;
- WindowPtr winptr;
- long result;
- int whichmenu, whichitem, keycode, numplanes, numshades;
- Rect boundrect;
- DialogPtr dialogptr;
- char *tmpbuff;
- FILE *debugfile;
- locator_measure locmeas;
- pickInformation pickinfo;
-
- /* STARTUP SPHIGS BASED ON USER'S ALLOCATION STRATEGY. */
- printf ("\nPlease enter number of framebuffer planes to allocate:\n");
- scanf ("%d", &numplanes);
- printf ("\nPlease enter number of shades per flexicolor:\n");
- printf (" (Note: this affects how many different flexicolors will be ");
- printf ("available.)\n");
- scanf ("%d", &numshades);
-
- SPH_begin (514,400, numplanes, numshades);
-
- /* INFORM USER OF FINAL OUTCOME OF HER STRATEGY SPEC. */
- tmpbuff = malloc(1000);
- sprintf (tmpbuff, "I can provide %d flexible colors and %d non-flex colors.",
- NUM_OF_FLEXICOLORS, (NUM_OF_APPL_SETTABLE_COLORS-NUM_OF_FLEXICOLORS));
- ReportSpecialError (tmpbuff, FALSE);
- free (tmpbuff);
-
- SPH_setImplicitRegenerationMode (SUPPRESSED);
-
- /* We hope there are enough flexicolors for these. */
- SPH_loadCommonColor (2, "yellow");
- SPH_loadCommonColor (3, "green");
- SPH_loadCommonColor (4, "turquoise");
- SPH_loadCommonColor (5, "pink");
- SPH_loadCommonColor (6, "goldenrod");
- SPH_loadCommonColor (7, "firebrick");
-
- /* But these need not be flexicolors. */
- SPH_loadCommonColor (red, "red");
- SPH_loadCommonColor (grey, "lightgrey");
- SPH_loadCommonColor (orange, "orange");
- SPH_loadCommonColor (yellow, "yellow");
- SPH_loadCommonColor (limegreen, "yellowgreen");
- SPH_loadCommonColor (forestgreen, "forestgreen");
- SPH_loadCommonColor (blue, "blue");
-
- InitAllViews();
- BuildEverything ();
-
- DisplayAllViews ();
- ShowUsingNewView1();
- SPH_postRoot (NEIGHBORHOOD_STRUCT, PERSPECTIVE_VIEW);
-
- ClearMenuBar();
- MakeMenuBar();
- CheckItem (rendermenu, currenderitem, TRUE);
- CheckItem (viewportmenu, 2, TRUE);
- CheckItem (gridmenu, 1, TRUE);
- CheckItem (chimneymenu, 3, TRUE);
-
- #define getmask (everyEvent)
-
-
- /* INITIALIZE THE GRANULARITY DIALOG BOX */
- DrawDialog (granDialogPtr = GetNewDialog (granDialogID, NULL, (WindowPtr)-1));
- GetDItem (granDialogPtr, 2, &whichmenu/*dummy*/,
- &grantextitemhandle, &boundrect/*dummy*/);
- DisplayMotionGranularity();
-
- SetRect (&boundrect, 0,40,3000,3000);
-
- InstallCameraDialog (2);
-
- top:
- if (!stillVirgin)
- SPH_setImplicitRegenerationMode (ALLOWED);
-
- SystemTask();
- GetNextEvent (getmask, &ev);
- if (ev.what == nullEvent) goto top;
-
- if (ev.what == keyDown)
- goto HandleKeyEvent;
-
- SPH_setImplicitRegenerationMode (SUPPRESSED);
-
- sortOfTop:
- if (IsDialogEvent(&ev)) {
- if (DialogSelect (&ev, &dialogptr, &whichitem))
- if (dialogptr == granDialogPtr) {
- switch (whichitem) {
- case 4: if ((motion_granularity += 5) > 99) motion_granularity = 99; break;
- case 5: if ((motion_granularity -= 5) < 1) motion_granularity = 1; break;
- case 3: InstallHelpDialog (granDialogID+400); break;
- }
- DisplayMotionGranularity();
- }
- else {
- int axis;
- double pitch=0.0, yaw=0.0;
- double bias = 1.0;
- switch (curCamDialogID) {
- case 301:
- axis=whichitem-1;
- if (axis>2) {
- axis -= 3;
- bias = -1.0;
- }
- ChangeVRP_relativeUVN (bias*motion_granularity, axis); break;
- case 302:
- axis=whichitem-1;
- if (axis>2) {
- axis -= 3;
- bias = -1.0;
- }
- ChangeVRP_relativeWC (bias*motion_granularity, axis); break;
- case 303:
- switch (whichitem) {
- case 4: pitch = (-motion_granularity); break;
- case 5: pitch = (+motion_granularity); break;
- case 2: yaw = (+motion_granularity); break;
- case 3: yaw = (-motion_granularity); break;
- }
- ChangeVPN (pitch, yaw); break;
- case 304:
- if (whichitem == 3)
- ChangePRPforOrtho();
- else if (whichitem == 4)
- ChangePRPforClosestPerspective();
- else
- ChangePRP ((double)((whichitem==1)?motion_granularity:-motion_granularity)); break;
- case 305:
- ChangeFrontClipPlane ((double)((whichitem==1)?motion_granularity:-motion_granularity)); break;
- case 306:
- ChangeBackClipPlane ((double)((whichitem==1)?motion_granularity:-motion_granularity)); break;
- }
- ShowUsingNewView1 ();
- }
- else { /* DialogSelect returned false */
- if ((ev.what == activateEvt) && ((ev.modifiers & activeFlag) != 0) &&
- (StillDown()) && (FindWindow (ev.where, &winptr) == inContent))
- if (((DialogPtr)(winptr) == granDialogPtr) ||
- ((DialogPtr)(winptr) == curCamDialogPtr)) {
- ev.what = mouseDown;
- goto sortOfTop;
- }
- }
-
- goto top;
- }
-
-
- switch (ev.what) {
- case updateEvt: goto HandleUpdateEvent; break;
- case mouseDown: goto HandleMouseEvent; break;
- }
- goto top;
-
- /*******/
-
- HandleKeyEvent:
- /* only fkeys are to be recognized and processed */
- keycode = (ev.message&keyCodeMask)>>8;
- switch (keycode) {
- case 0x7a: motion_granularity = 3* 1; break;
- case 0x78: motion_granularity = 3* 2; break;
- case 0x63: motion_granularity = 3* 3; break;
- case 0x76: motion_granularity = 3* 4; break;
-
- case 0x60: motion_granularity = 3* 5; break;
- case 0x61: motion_granularity = 3* 6; break;
- case 0x62: motion_granularity = 3* 7; break;
- case 0x64: motion_granularity = 3* 8; break;
-
- case 0x65: motion_granularity = 3* 9; break;
- case 0x6d: motion_granularity = 3*10; break;
- case 0x67: motion_granularity = 3*11; break;
- case 0x6f: motion_granularity = 3*12; break;
-
- case 0x69: motion_granularity = 3*13; break;
- case 0x6b: motion_granularity = 3*14; break;
- case 0x71: motion_granularity = 3*15; break;
- }
- DisplayMotionGranularity ();
- goto top;
-
-
- /*******/
-
- HandleUpdateEvent:
- if (srgpmac__cwindow == (WindowPtr)(ev.message)) {
- BeginUpdate (srgpmac__cwindow);
- if (stillVirgin) {
- SPH_setImplicitRegenerationMode (ALLOWED);
- stillVirgin = FALSE;
- }
- else
- SPH_regenerateScreen ();
- EndUpdate (srgpmac__cwindow);
- }
- goto top;
-
-
- HandleMouseEvent:
- switch (FindWindow (ev.where, &winptr)) {
- case inMenuBar:
- result = MenuSelect (ev.where);
- whichmenu = (result>>16);
- whichitem = (result&0xffff);
-
- if (whichitem == CountMItems(GetMHandle(whichmenu))) {
- InstallHelpDialog (whichmenu);
- HiliteMenu (0);
- break;
- }
-
- switch (whichmenu) {
-
- case pickmenuID:
- tmpdptr = GetNewDialog (25980, NULL, (WindowPtr)-1);
- GetDItem (tmpdptr, 2, &whichmenu/*dummy*/,
- &tmpitemhandle, &boundrect/*dummy*/);
- DrawDialog (tmpdptr);
- ClearMenuBar();
- SPH_setInputMode (LOCATOR, EVENT);
- tmpbuff = malloc(500);
- tryagain: SPH_waitEvent (-1);
- SPH_getLocator (&locmeas);
- if (locmeas.buttonChord[LEFT_BUTTON] == UP)
- goto tryagain;
- if (locmeas.view_index != PERSPECTIVE_VIEW)
- goto conclude;
- SPH_pickCorrelate (locmeas.position, locmeas.view_index,
- &pickinfo);
-
- if (pickinfo.pickLevel == 0) {
- SysBeep(10);
- sprintf (tmpbuff, "You picked on nothing.");
- CtoPstr (tmpbuff);
- SetIText (tmpitemhandle, tmpbuff);
- goto tryagain;
- }
- if (pickinfo.pickLevel == 4)
- sprintf (tmpbuff, "You picked the chimney on ");
- else
- sprintf (tmpbuff, "You picked ");
- sprintf (tmpbuff + strlen(tmpbuff), "house #%d ",
- 1 + (int)((pickinfo.path[1].elementIndex-1)/3));
- sprintf (tmpbuff + strlen(tmpbuff), "on street #%d.",
- 1 + (int)(pickinfo.path[0].elementIndex/2));
- CtoPstr (tmpbuff);
- SetIText (tmpitemhandle, tmpbuff);
- goto tryagain;
-
- conclude:
- free (tmpbuff);
- DisposDialog (tmpdptr);
- MakeMenuBar();
- break;
-
-
- case chimneymenuID:
- if (whichitem == curchimneymenuitem)
- break;
- CheckItem (chimneymenu, curchimneymenuitem, FALSE);
- if (whichitem == 1) {
- AddChimneyToHouse (HOUSE_STRUCT);
- AddChimneyToHouse (FAKE_HOUSE_TOP_STRUCT);
- AddChimneyToHouse (FAKE_HOUSE_SIDE_STRUCT);
- }
- else if (whichitem == 3) {
- TakeChimneyFromHouse (HOUSE_STRUCT);
- TakeChimneyFromHouse (FAKE_HOUSE_TOP_STRUCT);
- TakeChimneyFromHouse (FAKE_HOUSE_SIDE_STRUCT);
- }
- curchimneymenuitem = whichitem;
- CheckItem (chimneymenu, curchimneymenuitem, TRUE);
- /* BE CAREFUL -- no break should appear just above this line */
- if ( ! ((curHelpDialogID == 4236) || (curHelpDialogID == 4216)))
- break; /* careful!! conditional break! */
- /* CAREFUL -- the modelmenuID case MUST BE NEXT */
-
-
- case modelmenuID:
- /* If we got here, they definitely asked for us to display a dialog */
- InstallHelpDialog (606 + (10*curchimneymenuitem)); /* trick! */
- break;
-
-
- case gridmenuID:
- if (whichitem == curgridmenuitem)
- break; /*NOCHANGE*/
- CheckItem (gridmenu, curgridmenuitem, FALSE);
- if (whichitem == 1/*HIDE*/) {
- SPH_unpostRoot (GRID_STRUCT, PERSPECTIVE_VIEW);
- SPH_unpostRoot (GRID_STRUCT, TOP_ORTHO_VIEW);
- SPH_unpostRoot (GRID_STRUCT, SIDE_ORTHO_VIEW);
- }
- else {
- AddGridInFrontOfRoot (NEIGHBORHOOD_STRUCT, PERSPECTIVE_VIEW);
- AddGridInFrontOfRoot (FAKE_NEIGHBORHOOD_TOP_STRUCT, TOP_ORTHO_VIEW);
- AddGridInFrontOfRoot (FAKE_NEIGHBORHOOD_SIDE_STRUCT, SIDE_ORTHO_VIEW);
- }
- curgridmenuitem = whichitem;
- CheckItem (gridmenu, curgridmenuitem, TRUE);
- break;
-
-
-
- case viewportmenuID:
- if (whichitem == curvpmenuitem)
- break; /*NOCHANGE*/
- CheckItem (viewportmenu, curvpmenuitem, FALSE);
- SPH_setImplicitRegenerationMode (SUPPRESSED);
- if (whichitem == 1/*FULL SCREEN*/)
- DisplayOnlyFullRenderView();
- else
- DisplayAllViews();
- ShowUsingNewView1();
- SPH_setImplicitRegenerationMode (ALLOWED);
- curvpmenuitem = whichitem;
- CheckItem (viewportmenu, curvpmenuitem, TRUE);
- break;
-
- case cameramenuID:
- if (whichitem <= 6)
- InstallCameraDialog (whichitem);
- else if (whichitem == 8) {
- RestoreCameraToDefault ();
- ShowUsingNewView1 ();
- }
- else if (whichitem == 10)
- /* DisplayHelp (whichmenu) */;
- break;
- case rendermenuID:
- switch (whichitem) {
- case 2:
- SPH_setRenderingMode (PERSPECTIVE_VIEW, WIREFRAME_RAW); break;
- case 5:
- SPH_setRenderingMode (PERSPECTIVE_VIEW, WIREFRAME); break;
- case 6:
- SPH_setRenderingMode (PERSPECTIVE_VIEW, LIT_FLAT); break;
- }
- CheckItem (rendermenu, currenderitem, FALSE);
- currenderitem = whichitem;
- CheckItem (rendermenu, currenderitem, TRUE);
- break;
- }
- HiliteMenu (0);
- break;
- case inDrag:
- DragWindow (winptr, ev.where, &boundrect);
- break;
- case inContent:
- SelectWindow (winptr);
- break;
- case inGoAway:
- if (TrackGoAway (winptr, ev.where)) {
- if (winptr == srgpmac__cwindow) {
- SPH_end();
- ExitToShell();
- }
- else if (winptr == curHelpDialogPtr) {
- DisposDialog (curHelpDialogPtr);
- curHelpDialogID = 0;
- }
- }
- break;
- case inSysWindow:
- SystemClick (&ev, winptr);
- break;
- }
- goto top;
- }
-
-